// 引入
const express = require('express');
const { send } = require('express/lib/response');
const res = require('express/lib/response');
const db = require('../../utils/db');

// 配置路由
const jianliRouter = express.Router();

// 编写接口
jianliRouter.get('/jianli/get',(req,res)=>{ // 获取数据
    const page = req.query.page;
    const count = req.query.count;
    const sql = `select * from t_jianli limit ${(page-1)*count},${count}`;
    const sql2 = `select count(*) as total from t_jianli;`;
    db.query(sql,(err,data)=>{
        if(err){
            console.log(err)
            res.send({error:1,msg:err})
        }else{
            db.query(sql2,(err2,data2)=>{
                if(err2){
                    console.log(err2)
                    res.send({error:1,msg:err2})
                }else{
                    console.log(data2)
                    res.send({error:0,msg:'查询成功',data:data,total:data2[0].total})
                }
                
            })
           
        }
    })
})
//输入框查询
jianliRouter.get('/jianli/input',(req,res)=>{
    const sql = `SELECT * FROM t_jianli WHERE jianli_xm='${req.query.jianli_xm}'`
    const sql2 = `SELECT COUNT(*) as total FROM t_jianli WHERE jianli_xm = '${req.query.jianli_xm}'`
    db.query(sql,(err,data)=>{
        if(err){
            console.log(err)
            res.send({error:1,msg:err})
        }else{
            console.log(data)
            db.query(sql2,(err2,data2)=>{
                if(err2){
                    console.log(err2)
                    res.send({error:1,msg:err2})
                }else{
                    console.log(data2)
                    res.send({error:0,msg:'查询成功',data:data,total:data2[0].total})
                }
            })
        }
    })
})
//部门查询接口
jianliRouter.get('/jianli/bumen',(req,res)=>{
    const page = req.query.page;
    const count = req.query.count;
    const sql = `SELECT * FROM t_jianli WHERE jianli_xy='${req.query.jianli_xy}'`
    const sql2 = `SELECT COUNT(*) as total FROM t_jianli WHERE jianli_xy = '${req.query.jianli_xy}'`
    db.query(sql,(err,data)=>{
        if(err){
            console.log(err)
            res.send({error:1,msg:err})
        }else{
            console.log(data)
            db.query(sql2,(err2,data2)=>{
                if(err2){
                    console.log(err2)
                    res.send({error:1,msg:err2})
                }else{
                    console.log(data2)
                    res.send({error:0,msg:'查询成功',data:data,total:data2[0].total})
                }
            })
        }
    })
   
})
//学历查询
jianliRouter.get('/jianli/xueli',(req,res)=>{
    const sql = `SELECT * FROM t_jianli WHERE jianli_xl='${req.query.jianli_xl}'`
    const sql2 = `SELECT COUNT(*) as total FROM t_jianli WHERE jianli_xl = '${req.query.jianli_xl}'`
    db.query(sql,(err,data)=>{
        if(err){
            console.log(err)
            res.send({error:1,msg:err})
        }else{
            console.log(data)
            db.query(sql2,(err2,data2)=>{
                if(err2){
                    console.log(err2)
                    res.send({error:1,msg:err2})
                }else{
                    console.log(data2)
                    res.send({error:0,msg:'查询成功',data:data,total:data2[0].total})
                }
            })
        }
    })
})

//删除
jianliRouter.post('/jianli/del',(req,res)=>{
  const sql = `delete from t_jianli where jianli_id='${req.body.jianli_id}';`
  db.query(sql,(err,data)=>{
if(err){
  console.log(err)
  res.send({error:1,msg:err})
}else{
  res.send({error:0,msg:'删除成功'})

}
  })
})




//面试安排数据渲染
jianliRouter.get('/mianshi/get',(req,res)=>{ // 获取数据
  const page = req.query.page;
  const count = req.query.count;
  const sql = `select * from t_mianshi limit ${(page-1)*count},${count}`;
  const sql2 = `select count(*) as total from t_mianshi;`;
  db.query(sql,(err,data)=>{
      if(err){
          console.log(err)
          res.send({error:1,msg:err})
      }else{
          db.query(sql2,(err2,data2)=>{
              if(err2){
                  console.log(err2)
                  res.send({error:1,msg:err2})
              }else{
                  console.log(data2)
                  res.send({error:0,msg:'查询成功',data:data,total:data2[0].total})
              }
              
          })
         
      }
  })
})

//面试地址查询
jianliRouter.get('/mianshi/dizhi',(req,res)=>{
  const sql = `SELECT * FROM t_mianshi WHERE mianshi_dz='${req.query.mianshi_dz}'`
  const sql2 = `SELECT COUNT(*) as total FROM t_mianshi WHERE mianshi_dz = '${req.query.mianshi_dz}'`
  db.query(sql,(err,data)=>{
      if(err){
          console.log(err)
          res.send({error:1,msg:err})
      }else{
          console.log(data)
          db.query(sql2,(err2,data2)=>{
              if(err2){
                  console.log(err2)
                  res.send({error:1,msg:err2})
              }else{
                  console.log(data2)
                  res.send({error:0,msg:'查询成功',data:data,total:data2[0].total})
              }
          })
      }
  })
})

//面试状态查询
jianliRouter.get('/mianshi/zhuangtai',(req,res)=>{
  const sql = `SELECT * FROM t_mianshi WHERE mianshi_zt='${req.query.mianshi_zt}'`
  const sql2 = `SELECT COUNT(*) as total FROM t_mianshi WHERE mianshi_zt = '${req.query.mianshi_zt}'`
  db.query(sql,(err,data)=>{
      if(err){
          console.log(err)
          res.send({error:1,msg:err})
      }else{
          console.log(data)
          db.query(sql2,(err2,data2)=>{
              if(err2){
                  console.log(err2)
                  res.send({error:1,msg:err2})
              }else{
                  console.log(data2)
                  res.send({error:0,msg:'查询成功',data:data,total:data2[0].total})
              }
          })
      }
  })
})







//面试表数据删除
jianliRouter.post('/mianshi/del',(req,res)=>{
  const sql = `delete from t_mianshi where mianshi_id='${req.body.mianshi_id}';`
  db.query(sql,(err,data)=>{
if(err){
  console.log(err)
  res.send({error:1,msg:err})
}else{
  res.send({error:0,msg:'删除成功'})

}
  })
})


//黑名单数据渲染
jianliRouter.get('/hei/get',(req,res)=>{ // 获取数据
  const page = req.query.page;
  const count = req.query.count;
  const sql = `select * from t_heimingdan limit ${(page-1)*count},${count}`;
  const sql2 = `select count(*) as total from t_heimingdan;`;
  db.query(sql,(err,data)=>{
      if(err){
          console.log(err)
          res.send({error:1,msg:err})
      }else{
          db.query(sql2,(err2,data2)=>{
              if(err2){
                  console.log(err2)
                  res.send({error:1,msg:err2})
              }else{
                  console.log(data2)
                  res.send({error:0,msg:'查询成功',data:data,total:data2[0].total})
              }
              
          })
         
      }
  })
})
//原因查询
jianliRouter.get('/hei/yuanyin',(req,res)=>{
  const sql = `SELECT * FROM t_heimingdan WHERE hei_yy='${req.query.hei_yy}'`
  const sql2 = `SELECT COUNT(*) as total FROM t_heimingdan WHERE hei_yy = '${req.query.hei_yy}'`
  db.query(sql,(err,data)=>{
      if(err){
          console.log(err)
          res.send({error:1,msg:err})
      }else{
          console.log(data)
          db.query(sql2,(err2,data2)=>{
              if(err2){
                  console.log(err2)
                  res.send({error:1,msg:err2})
              }else{
                  console.log(data2)
                  res.send({error:0,msg:'查询成功',data:data,total:data2[0].total})
              }
          })
      }
  })
})
//黑名单删除
jianliRouter.post('/hei/del',(req,res)=>{
  const sql = `delete from t_heimingdan where hei_id='${req.body.hei_id}';`
  db.query(sql,(err,data)=>{
if(err){
  console.log(err)
  res.send({error:1,msg:err})
}else{
  res.send({error:0,msg:'删除成功'})

}
  })
})

//录用审批

jianliRouter.get('/luyong/get',(req,res)=>{ // 获取数据
    const page = req.query.page;
    const count = req.query.count;
    const sql = `select * from t_luyong limit ${(page-1)*count},${count}`;
    const sql2 = `select count(*) as total from t_luyong;`;
    db.query(sql,(err,data)=>{
        if(err){
            console.log(err)
            res.send({error:1,msg:err})
        }else{
            db.query(sql2,(err2,data2)=>{
                if(err2){
                    console.log(err2)
                    res.send({error:1,msg:err2})
                }else{
                    console.log(data2)
                    res.send({error:0,msg:'查询成功',data:data,total:data2[0].total})
                }
                
            })
           
        }
    })
})
//输入框查询
jianliRouter.get('/luyong/input',(req,res)=>{
    const sql = `SELECT * FROM t_luyong WHERE luyong_xm='${req.query.luyong_xm}'`
    const sql2 = `SELECT COUNT(*) as total FROM t_luyong WHERE luyong_xm = '${req.query.luyong_xm}'`
    db.query(sql,(err,data)=>{
        if(err){
            console.log(err)
            res.send({error:1,msg:err})
        }else{
            console.log(data)
            db.query(sql2,(err2,data2)=>{
                if(err2){
                    console.log(err2)
                    res.send({error:1,msg:err2})
                }else{
                    console.log(data2)
                    res.send({error:0,msg:'查询成功',data:data,total:data2[0].total})
                }
            })
        }
    })
})
//部门查询接口
jianliRouter.get('/luyong/bumen',(req,res)=>{
    const page = req.query.page;
    const count = req.query.count;
    const sql = `SELECT * FROM t_luyong WHERE luyong_bm='${req.query.luyong_bm}'`
    const sql2 = `SELECT COUNT(*) as total FROM t_luyong WHERE luyong_bm = '${req.query.luyong_bm}'`
    db.query(sql,(err,data)=>{
        if(err){
            console.log(err)
            res.send({error:1,msg:err})
        }else{
            console.log(data)
            db.query(sql2,(err2,data2)=>{
                if(err2){
                    console.log(err2)
                    res.send({error:1,msg:err2})
                }else{
                    console.log(data2)
                    res.send({error:0,msg:'查询成功',data:data,total:data2[0].total})
                }
            })
        }
    })
   
})
//学历查询
jianliRouter.get('/luyong/xueli',(req,res)=>{
    const sql = `SELECT * FROM t_luyong WHERE luyong_xl='${req.query.luyong_xl}'`
    const sql2 = `SELECT COUNT(*) as total FROM t_luyong WHERE luyong_xl = '${req.query.luyong_xl}'`
    db.query(sql,(err,data)=>{
        if(err){
            console.log(err)
            res.send({error:1,msg:err})
        }else{
            console.log(data)
            db.query(sql2,(err2,data2)=>{
                if(err2){
                    console.log(err2)
                    res.send({error:1,msg:err2})
                }else{
                    console.log(data2)
                    res.send({error:0,msg:'查询成功',data:data,total:data2[0].total})
                }
            })
        }
    })
})
//删除
jianliRouter.post('/luyong/del',(req,res)=>{
    const sql = `delete from t_luyong where luyong_id='${req.body.luyong_id}';`
    db.query(sql,(err,data)=>{
if(err){
    console.log(err)
    res.send({error:1,msg:err})
}else{
    res.send({error:0,msg:'删除成功'})

}
    })
})

//导出
module.exports = jianliRouter;